<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .detail {
            color: #3c3c3c;
            margin: 20px auto 0;
            position: relative;
            z-index: 111;
            font-family: tahoma, arial;
        }

        .detail-bd {
            border: 1px solid #e8e8e8;
            margin-bottom: 20px;
        }

        .summary {

            float: left;
            width: 100%;
        }

        .item-info .left {
            display: inline;
            float: left;
            padding: 20px 0 20px 20px;
            width: 400px;
            position: relative;
        }

        .item-info .left .gallery {
            margin-bottom: 18px;
            overflow: hidden;
            width: 400px;
        }

        .item-info .left .main-pic {
            position: relative;
            margin-bottom: 15px;
            z-index: 1;
            background: #f7f7f7;
            height: 400px;
            overflow: hidden;
            width: 400px;
            display: table-cell;
            text-align: center;
            vertical-align: middle;
        }

        .item-info .left ul li {
            display: inline;
            float: left;
            margin-right: 9px;
            width: 50px;
            height: 50px;
            border: 2px solid #fff;
            transition-property: border-color;
            transition-duration: .2s;
            overflow: hidden;
        }

        .item-info .left ul li.hover {
            border-color: #f40;
        }

        .clearfix:after {
            clear: both;
            content: ".";
            display: block;
            height: 0;
            line-height: 0;
            visibility: hidden;
        }

        .item-info .right {
            display: inline;
            float: left;
            padding: 0 20px 20px 0;
            width: 498px;
        }

        .item-info .right .wrap {
            padding-left: 18px;
            position: relative;
            z-index: 222;
        }

        .item-info .right .title {
            padding: 20px 0 10px;
        }

        .item-info .right .title h3 {
            min-height: 21px;
            font-size: 16px;
            font-weight: 700;
            line-height: 21px;
            color: #3c3c3c;
            font-family: arial, "microsoft yahei";
        }

        .item-info .right .title p {
            color: #e3393c;
            margin: 5px 0;
            font-size: 14px;
            line-height: 22px;
            padding: 0 0 15px;
            border-bottom: 1px dotted #d9d9d9;
            font-weight: bold;
        }

        .item-info .right .promo-meta {
            z-index: 7;
            position: relative;
            min-height: 35px;
            zoom: 1;
            padding-bottom: 10px;
            border-bottom: 1px dotted #d9d9d9;
            font-family: "微软雅黑";
        }

        .item-info .right .promo-meta li {
            /* width: 350px; */
            line-height: 26px;
            margin-bottom: 5px;
        }

        .buy_box {
            margin: 20px 0 18px;
            position: relative;
            z-index: 6;
            padding: 1px;
        }

        .sep-line {
            height: 0;
            border-bottom: 1px dotted #d9d9d9;
            margin: 10px 0;
            position: relative;
            z-index: 1;
            clear: both;
            overflow: hidden;
            zoom: 1;
        }

        .social {
            padding-top: 10px;
            position: relative;
            z-index: 5;
        }

        .bshare-custom {
            padding-top: 10px;
        }

        .hidden {
            display: none;
        }

        .clear {
            clear: both;
        }

        #cart_show {
            overflow: hidden;
            padding: 7px;
            position: absolute;
            z-index: 99999999;
        }

        .choose_btn .btn-buy {
            float: left;
            cursor: pointer;
            display: block;
            height: 41px;
            width: 136px;
            background: url(../images/zxy/buy.png) no-repeat;
        }

        .choose_btn .add-cart {
            float: left;
            cursor: pointer;
            display: block;
            height: 41px;
            width: 136px;
            background: url(../images/zxy/buy.png) no-repeat;
            margin-left: 10px;
            width: 182px;
            background-position: right 0;
        }
    </style>
</head>

<body>
    <div class="detail">
        <div class="detail-bd clearfix">
            <div class="summary clearfix">
                <div class="item-info clearfix">
                    <div class="left">
                        <!-- <div class="gallery">
                            <div class="main-pic">
                                <a target="_blank"
                                    href="https://img.zhuego.com/user/7407991/2020/0722/20200722043332848.jpg">
                                    <img class="jqzoom" width="400" height="400"
                                        src="https://img.zhuego.com/user/7407991/2020/0722/20200722043332848.jpg"
                                        rel="https://img.zhuego.com/user/7407991/2020/0722/20200722043332848.jpg"
                                        title="【绿健兽药】 母仔安散100g母子安母仔同治增加奶水预防仔猪黄白痢增强母仔抗病力 "
                                        alt="【绿健兽药】 母仔安散100g母子安母仔同治增加奶水预防仔猪黄白痢增强母仔抗病力 ">
                                </a>
                            </div>
                            <ul id="jqzoom" class="clearfix">
                                <li class="hover"><img
                                        src="https://img.zhuego.com/user/7407991/2020/0722/20200722043332848.jpg"
                                        big="https://img.zhuego.com/user/7407991/2020/0722/20200722043332848.jpg"
                                        height="60" width="60" alt="【绿健兽药】 母仔安散100g母子安母仔同治增加奶水预防仔猪黄白痢增强母仔抗病力 "></li>
                                <li class=""><img
                                        src="https://img.zhuego.com/user/7407991/2020/0722/20200722043351543.jpg"
                                        big="https://img.zhuego.com/user/7407991/2020/0722/20200722043351543.jpg"
                                        height="60" width="60" alt="【绿健兽药】 母仔安散100g母子安母仔同治增加奶水预防仔猪黄白痢增强母仔抗病力 "></li>
                                <li class=""><img
                                        src="https://img.zhuego.com/user/7407991/2020/0722/20200722043359894.jpg"
                                        big="https://img.zhuego.com/user/7407991/2020/0722/20200722043359894.jpg"
                                        height="60" width="60" alt="【绿健兽药】 母仔安散100g母子安母仔同治增加奶水预防仔猪黄白痢增强母仔抗病力 "></li>
                                <li class=""><img
                                        src="https://img.zhuego.com/user/7407991/2020/0722/20200722043408975.jpg"
                                        big="https://img.zhuego.com/user/7407991/2020/0722/20200722043408975.jpg"
                                        height="60" width="60" alt="【绿健兽药】 母仔安散100g母子安母仔同治增加奶水预防仔猪黄白痢增强母仔抗病力 "></li>
                            </ul>
                        </div> -->
                    </div>
                    <div class="right">
                        <!-- <div class="wrap">
                            <div class="title">
                                <h3>【绿健兽药】 母仔安散100g母子安母仔同治增加奶水预防仔猪黄白痢增强母仔抗病力 </h3>
                                <p>促销信息：【满赠】：满2送1，母仔安散100g </p>
                            </div>
                            <ul class="promo-meta clearfix">

                                <li>
                                    <span class="th_tit">市场价:</span>
                                    <strong class="del">
                                        <em class="rmb"></em>
                                        <em class="rmb-num">8.00(袋)</em>
                                    </strong>
                                </li>

                                <li>
                                    <span class="th_tit">价&nbsp;&nbsp;格:</span>

                                    <strong class="promo-price">
                                        <em class="rmb"></em>
                                        <em id="price" class="rmb-num">5.00</em>
                                        <em class="rmb-num">(袋)</em>
                                    </strong>
                                </li>

                                <li>
                                    <p>
                                        快递:&nbsp; ￥ 10.00
                                        &nbsp;&nbsp;满200.00元 包邮
                                    </p>
                                </li>
                                <li class="counter">
                                    <p>
                                        <span class="sell-counter">
                                            <a href="javascript:;">
                                                成交<b>0</b>件
                                            </a>
                                        </span>
                                    </p>
                                </li>
                            </ul>
                            <div class="buy_box clearfix">
                                <form id="form" onsubmit="return buy()"
                                    action="index.php?m=order&amp;c=manage&amp;a=confirm_order" method="post">
                                    <input name="ac" id="ac" type="hidden" value="buy">
                                    <input name="productid" type="hidden" value="6572">
                                    <input name="sid" id="sid" type="hidden" value="0">
                                    <div class="select_style clearfix">
                                        <dt>数&nbsp;&nbsp;量:</dt>
                                        <dd class="stock">
                                            <a href="javascript:void(0);" id="low_num">-</a>
                                            <input onkeyup="check_nums();" size="3" name="nums" id="nums" type="text"
                                                value="1">
                                            <a href="javascript:void(0);" id="add_num">+</a>
                                        </dd>
                                    </div>
                                    <div class="choose_btn">
                                        <a href="javascript:;" class="btn-buy" id="btn-buy" rel="bth-buy"></a>
                                        <a href="shopcar.html" class="add-cart"></a>
                                    </div>
                                </form>
                            </div>
                            <div class="sep-line clearfix"></div>
                        </div> -->
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="../js/ajax.js"></script>
    <script src="../js/jquery-1.9.1.min.js"></script>
    <script>
        $(document).ready(function () {
            $("img").each(function (i) {
                if ($(this).attr('alt') == '') {
                    $(this).attr('alt', 'alt信息为空');
                }
            });
            $(".add-cart").click(function () {
                var flag = buy(); if (flag) {
                    var num = parseInt($('#nums').val());
                    if (!num) {
                        alert('亲~加入购物车数量不能为空哦')
                        return false;
                    }
                    var price = "5.00";
                    var sid = $('#sid').val();
                    var pid = '6572';

                    $.getJSON("api.php", { op: "cart", ac: "add", price: price, nums: num, pid: pid, sid: sid }, function (json) {
                        if (json.status < 0) {
                            alert(json.msg);
                            if (json.status == -1) {
                                window.location.href = 'index.php?m=member&c=index&a=login&forward=' + self.location.href;
                            } else {
                                window.location.href = self.location.href;
                            }

                            return false;
                        } else {
                            $('#cart_show').fadeIn(500);
                            $('#cartShowMsg').text(json.msg);
                            $('#cartNum').text(json.nums);
                            if (json.status == 1) {
                                $('#cartShowMsg').addClass("cart-head");
                            } else {
                                $('#cartShowMsg').addClass("cart-err");
                            }
                            var x = $(".buy_box").offset();
                            $("#cart_show").offset({ top: x.top, left: x.left });
                            $('#cart_show').fadeIn(500);
                        }
                    });

                    return false;
                }
            });
            $("#low_num").click(function () {
                var num = $('#nums').val() * 1;
                if (num > 1)
                    $('#nums').val(num - 1);
                check_nums()
            });
            $("#add_num").click(function () {
                var num = $('#nums').val() * 1;
                if (num < $('#stock').html())
                    $('#nums').val(num + 1);
                check_nums()
            });

            $(".jqzoom").mouseover(function () {
                DrawImage(this, 400, 400)
            });

        });

        
        $(window).load(function () {
            $(".main-pic img").each(function () {
                DrawImage(this, 400, 400);
            });
        });
        $('#jqzoom li').hover(function () {
            $(this).addClass("hover").siblings().removeClass("hover");;
        });
        // $("#jqzoom li").mouseover(function () {
        //     $(".jqzoom").attr('src', $(this).find("img").attr("big"));
        //     $(".jqzoom").attr('rel', $(this).find("img").attr("big"));
        //     $(".jqzoom").each(function () {
        //         DrawImage(this, 400, 400);
        //     });
        // });

        //按图片实际长宽显示图片
        function DrawImage(ImgD, FitWidth, FitHeight) {
            var image = new Image();
            image.src = ImgD.src;
            if (image.width > 0 && image.height > 0) {
                if (image.width / image.height >= FitWidth / FitHeight) {
                    if (image.width > FitWidth) {
                        ImgD.width = FitWidth;
                        ImgD.height = (image.height * FitWidth) / image.width;
                    } else {
                        ImgD.width = image.width;
                        ImgD.height = image.height;
                    }
                } else {
                    if (image.height > FitHeight) {
                        ImgD.height = FitHeight;
                        ImgD.width = (image.width * FitHeight) / image.height;
                    } else {
                        ImgD.width = image.width;
                        ImgD.height = image.height;
                    }
                }
                if (image.width >= 600 || image.height >= 600) {
                    $(".jqzoom").imagezoom();//放大图片功能
                }
            }
        }


        function spec(id, spec, price, stock) {
            this.id = id;
            this.spec = spec;
            this.price = price;
            this.stock = stock;
        }
        function goodsspec(specs, specQty, defSpec) {
            this.specs = specs;
            this.specQty = specQty;
            this.defSpec = defSpec;
            this.spec1 = null;
            this.spec2 = null;
            if (this.specQty >= 1) {
                for (var i = 0; i < this.specs.length; i++) {
                    if (this.specs[i].id == this.defSpec) {
                        break;
                    }
                }
            }
            this.getSpec = function () {
                for (var i = 0; i < this.specs.length; i++) {
                    return this.specs[i];
                }
                return null;
            }
        }
        function selectSpec(num, obj, SID) {
            goodsspec['spec' + num] = SID;
            var id = $(obj).parent().parent().parent().parent().attr('id');
            if (id == 'color') {
                var data_str = $(obj).attr('data-param');
                if (data_str) {
                    eval("data_str = " + data_str);
                    $('.jqzoom').attr("src", data_str.src);
                    $('.jqzoom').attr("rel", data_str.src);
                }
                else {
                    var src = "https://img.zhuego.com/user/7407991/2020/0722/20200722043332848.jpg";
                    $('.jqzoom').attr("src", src);
                    $('.jqzoom').attr("rel", src);
                }
            }

            $(obj).addClass("checked");
            $(obj).parents('li').siblings().find('a').removeClass("checked");

            var spec = goodsspec.getSpec();
            var sign = 't';
            $('ul[genre="property"]').each(function () {
                if (!$(this).find('a').hasClass('checked')) {
                    sign = 'f';
                }
            });
            if (spec != null && sign == 't') {
                $('#stock').html(spec.stock);
                $('#price').html(spec.price.toFixed(2));
                $('#sid').val(spec.id);

                if (parseInt(spec.stock) == 0) {
                    $('.choose_result').show().html('<div class="dd"><em>库存量不足，请选择其它。</em></div>');
                    $('#addcart_submit').attr('disabled', true).css('cursor', 'pointer');
                }
                else {
                    SP_V = '';
                    $('ul[genre="property"]').find('li > .checked').each(function (i) {
                        SP_V += '<strong>"' + $(this).text() + '"</strong>，';
                    });
                    SP_V = SP_V.substr(0, SP_V.length - 1);
                    $('.choose_result').show().html('<em>您选择了：</em>' + SP_V + '');
                    $('#addcart_submit').attr('disabled', false).css('cursor', 'auto');
                    $('#nums').val("1");
                }
            }
        }
        var specs = new Array();
        specs.push(new spec('', '', '', '', ''));
        var specQty = 0;
        var defSpec = 0;
        var goodsspec = new goodsspec(specs, specQty, defSpec);
        $(".inner-wrap li").click(function () {
            var b = $(".inner-wrap li").index($(this));
            $(this).addClass("cur").siblings().removeClass("cur");
            $(".con .i-con").eq(b).show().siblings(".i-con").hide();
        });




        function queryString(attr) {
            let n = window.location.href.indexOf('?')
            let arr = window.location.href.slice(n + 1).split('&')
            let obj = {}

            arr.forEach(function (ele, index) {
                obj[ele.split('=')[0]] = ele.split('=')[1]
            })

            return obj[attr]
        }

        // console.log()

        let left = document.querySelector('.left')
        let right = document.querySelector('.right')
        pAjax({
            url: '../server/detail.php',
            data: {
                id: queryString('id') - 0 // localStorage.getItem('detailId') - 0
            }
        }).then(function (res) {
            let json = JSON.parse(res)
            console.log(json)
            left.innerHTML = `
                <div class="gallery">
                            <div class="main-pic">
                                <a target="_blank"
                                    href="${json.img}">
                                    <img class="jqzoom" width="400" height="400"
                                        src="${json.img}"
                                       
                                        title="${json.word}"
                                        alt="${json.word}">
                                </a>
                            </div>
                            <ul id="jqzoom" class="clearfix">
                                <li class="hover"><img
                                        src="${json.img}"
                                        big="${json.img}"
                                        height="60" width="60" alt="${json.word}"></li>
                                <li class=""><img
                                        src="https://img.zhuego.com/user/7407991/2020/0722/20200722043351543.jpg"
                                        big="https://img.zhuego.com/user/7407991/2020/0722/20200722043351543.jpg"
                                        height="60" width="60" alt="【绿健兽药】 母仔安散100g母子安母仔同治增加奶水预防仔猪黄白痢增强母仔抗病力 "></li>
                                <li class=""><img
                                        src="https://img.zhuego.com/user/7407991/2020/0722/20200722043359894.jpg"
                                        big="https://img.zhuego.com/user/7407991/2020/0722/20200722043359894.jpg"
                                        height="60" width="60" alt="【绿健兽药】 母仔安散100g母子安母仔同治增加奶水预防仔猪黄白痢增强母仔抗病力 "></li>
                                <li class=""><img
                                        src="https://img.zhuego.com/user/7407991/2020/0722/20200722043408975.jpg"
                                        big="https://img.zhuego.com/user/7407991/2020/0722/20200722043408975.jpg"
                                        height="60" width="60" alt="【绿健兽药】 母仔安散100g母子安母仔同治增加奶水预防仔猪黄白痢增强母仔抗病力 "></li>
                            </ul>
                        </div>`
            right.innerHTML = `
                    <div class="wrap">
                            <div class="title">
                                <h3>${json.word}</h3>
                                <p>促销信息：【满赠】：满2送1，母仔安散100g </p>
                            </div>
                            <ul class="promo-meta clearfix">

                                <li>
                                    <span class="th_tit">市场价:</span>
                                    <strong class="del">
                                        <em class="rmb"></em>
                                        <em class="rmb-num">${json.price*1.2}</em>
                                    </strong>
                                </li>

                                <li>
                                    <span class="th_tit">价&nbsp;&nbsp;格:</span>

                                    <strong class="promo-price">
                                        <em class="rmb"></em>
                                        <em id="price" class="rmb-num">${json.price}</em>
                                        <em class="rmb-num"></em>
                                    </strong>
                                </li>

                                <li>
                                    <p>
                                        快递:&nbsp; ￥ 10.00
                                        &nbsp;&nbsp;满200.00元 包邮
                                    </p>
                                </li>
                                <li class="counter">
                                    <p>
                                        <span class="sell-counter">
                                            <a href="javascript:;">
                                                成交<b>${json.number}</b>件
                                            </a>
                                        </span>
                                    </p>
                                </li>
                            </ul>
                            <div class="buy_box clearfix">
                                <form id="form" onsubmit="return buy()"
                                    action="index.php?m=order&amp;c=manage&amp;a=confirm_order" method="post">
                                    <input name="ac" id="ac" type="hidden" value="buy">
                                    <input name="productid" type="hidden" value="6572">
                                    <input name="sid" id="sid" type="hidden" value="0">
                                    <div class="select_style clearfix">
                                        <dt>数&nbsp;&nbsp;量:</dt>
                                        <dd class="stock">
                                            <a href="javascript:void(0);" id="low_num">-</a>
                                            <input onkeyup="check_nums();" size="3" name="nums" id="nums" type="text"
                                                value="1">
                                            <a href="javascript:void(0);" id="add_num">+</a>
                                        </dd>
                                    </div>
                                    <div class="choose_btn">
                                        <a href="javascript:;" class="btn-buy" id="btn-buy" rel="bth-buy"></a>
                                        <a href="shopcar.html" class="add-cart"></a>
                                    </div>
                                </form>
                            </div>
                            <div class="sep-line clearfix"></div>
                        </div>`
            // oMedia.innerHTML = `<div class="media-left">
            //     <a href="javascript:;">
            //         <img class="media-object" src="${json.goods_big_logo}" alt="...">
            //     </a>
            // </div>
            // <div class="media-body">
            //     <h4 class="media-heading">${json.goods_name}</h4>
            //     <p>￥${json.goods_price}</p>
            // </div>`
        })
    </script>
</body>

</html>